package org.jeecg.modules.API.until;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class RabbitmqUntil {

    static Connection m_connection = null;
    public static Channel getMqChannel() throws IOException, TimeoutException {

        if(m_connection == null){
            // 创建连接工厂
            ConnectionFactory factory = new ConnectionFactory();
            //设置RabbitMQ地址
            factory.setHost("localhost");
            //创建一个新的连接
            m_connection = factory.newConnection();
        }
        //创建一个通道
        return m_connection.createChannel();
    }

}
